package cn.wolfcode.business.controller;

import cn.wolfcode.business.domain.BusStatement;
import cn.wolfcode.business.service.IBusStatementService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 结算单Controller
 * 
 * @author wolfcode
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/business/statement")
public class BusStatementController extends BaseController
{
    @Autowired
    private IBusStatementService busStatementService;

    @GetMapping("/list")
    public TableDataInfo list(BusStatement busStatement){
        startPage();
        Map<String,Object> map = busStatement.getParams();
        if (map != null){
            String endActualArrivalTime = (String) map.get("endActualArrivalTime");
            if ( endActualArrivalTime != null) {
                map.put("endActualArrivalTime", endActualArrivalTime + " 23:59:59");
            }
        }
        List<BusStatement> list = busStatementService.selectBusStatementList(busStatement);
        return getDataTable(list);
    }
    @GetMapping(value = "/list",headers = "cmd=list")
    public AjaxResult listServiceItem1(BusStatement busStatement){
        List<BusStatement> list = busStatementService.selectBusStatementList(busStatement);
        return AjaxResult.success(list);
    }
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Long id){
        return AjaxResult.success(busStatementService.selectBusStatementById(id));
    }
    @PostMapping
    public AjaxResult add(@RequestBody BusStatement busStatement){
        return toAjax(busStatementService.insertBusStatement(busStatement));
    }
//    @PostMapping("/{id}")
//    public AjaxResult general(@RequestBody BusAppointment busAppointment){
//        return toAjax(busStatementService.general(busAppointment));
//    }

    @PutMapping
    public AjaxResult edit(@RequestBody BusStatement busStatement){
        return toAjax(busStatementService.updateBusStatement(busStatement));
    }
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id){
        return toAjax(busStatementService.deleteBusStatementByIds(id));
    }
    @PostMapping("/{id}/appointment")
    public AjaxResult createStatement(@PathVariable Long id){
        Long statementId = busStatementService.createStatement(id);
        return AjaxResult.success(statementId);
    }
}
